<div id="tableWrapperID">
  <div id="tableWrapperHeaderID">
    <span>
      <%=t('form.title.statistic.date')%>
    </span>
  </div>
  <div id="tableWrapperBodyID" class="statistic-table-wrapper-body">
    <%= form_tag('/show_statistic_by_date', :id =>"statisticDateFormId", :remote => true, :class => "statisticForm") do -%>
        <div class="statistic-form-wrapper">
          <%= label_tag "date_from_id", t('field.common.date_from'), :class => "statistic-date-label-left"%>
          <%= text_field_tag "date_from", Date.today-1.month, :id=>"date_from_id", :readonly => true, :class => "statistic-date-field"%>
          <%= label_tag "date_to_id", t('field.common.date_to'), :class => "statistic-date-label"%>
          <%= text_field_tag "date_to", Date.today, :id=>"date_to_id", :readonly => true, :class => "statistic-date-field"%>
          <%= label_tag "transaction_type_id", t('field.transaction.type'), :class => "statistic-date-label"%>
          <%= select_tag "transaction_type", getTransactionTypesOptionList.html_safe, :id => "transaction_type_id", :class => "statistic-transaction-type" %>
          <%= label_tag "category_id", t('field.transaction.category'), :class => "statistic-date-label"%>
          <%= select_tag "category",  options_from_collection_for_select(@categories, "id", "name"), :include_blank => true, :id => "category_id"%>
        </div>
    <% end -%>
  </div>
</div>
<div id="chartContainer" class="statistic-graph-wrapper"></div>

<script type="text/javascript">
    var TRANSACTION_FROM_ACCOUNT_TO_CATEGORY = '<%=Transaction::TRANSACTION_FROM_ACCOUNT_TO_CATEGORY.to_s(10)%>';
    var TRANSACTION_FROM_CASH_TO_CATEGORY = '<%=Transaction::TRANSACTION_FROM_CASH_TO_CATEGORY.to_s(10)%>';

    jQuery(document).ready(function(){
        jQuery('#transaction_type_id').change(function(){
            var transaction_type = jQuery('#transaction_type_id').val();
            if(transaction_type == TRANSACTION_FROM_ACCOUNT_TO_CATEGORY
                    || transaction_type == TRANSACTION_FROM_CASH_TO_CATEGORY){
                jQuery('#category_id').removeAttr("disabled");
            }else{
                jQuery('#category_id').attr("disabled",true);
            }
            jQuery('#statisticDateFormId').submit();
        });
        jQuery('#category_id').change(function(){
            jQuery('#statisticDateFormId').submit();
        });
        initStatisticByDateChartOptions('<%=t('form.title.statistic.date')%>','<%=t('field.common.date')%>','<%=t('field.transaction.summa')%>');
        statisticInit();
    });
</script>